package com.mao.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Email;
import java.util.List;

/*
user：mao
data：2021/1/30
note：
*/
//不同于@Value,使用该注解可以批量注入属性，并且支持
//松散绑定：配置文件中属性为 last_name,Java 类中的属性可以为lastName
@ConfigurationProperties(prefix = "person")
@Component //必需进行添加的注解，不添加造成不能自动注入属性。
@Validated  //配合@Email使用，否则@Email注解不会起到任何作用。
public class Person {

    //@Value("${person.name}")
    String name;

    private String gender;

    //@Value 方式可以进行支持SpEL
    //@Value("#{1+2}")
    Integer age;
    @Email
//   @Value("${person.email}")
    String email;
    List<String> likes;

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Person(String name, String gender, Integer age, @Email String email, List<String> likes) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.email = email;
        this.likes = likes;
    }

    public Person(String name, String gender, Integer age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                ", email='" + email + '\'' +
                ", likes=" + likes +
                '}';
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public List<String> getLikes() {
        return likes;
    }

    public void setLikes(List<String> likes) {
        this.likes = likes;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}
